<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>无标题文档</title>
		<link href="../../css/style.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../laydate/laydate.js"></script>
		<script type="text/javascript" src="../../js/api.js"></script>
		<script type="text/javascript" src="../../js/axios.js"></script>
		<script type="text/javascript" src="../../js/jquery.js"></script>
		<script type="text/javascript" src="../../js/system/user/userAdd.js"></script>
		<script type="text/javascript">
			let user
			$(() => {
				getjobs()
				getDepts()
				const uid = location.search.split("=")[1];
				axiosRequest1("get", "/user/userInfo/" + uid).then(res => {
					if (res.data.code === 200) {
						user = res.data.data
						const {
							birthday,
							dept,
							deptId,
							id,
							job,
							jobId,
							phone,
							sex,
							statu,
							uname,
							password
						} = res.data.data
						$('#uid').val(id)
						$('#username').val(uname)
						$('#password').val(password)
						$('#phone').val(phone)
						$('#birthday').val(birthday)
						if (sex === 1) $('#male').attr("checked", 'checked')
						else $('#womale').attr("checked", "checked")
						$('#statuSelect').val(statu)
						$('#dept').val(deptId)
						$('#job').val(jobId)
					} else {
						let warninfo = $('#warninfo')
						warninfo.text("数据获取失败")
						warninfo.show()
						setTimeout(() => {
							warninfo.hide()
						}, 2000)
					}
				}, err => {
					console.log(err);
				})

			})

			function updateUser() {
				if (!verificateFiled("username") || !verificateFiled("password") ||
					!verificateFiled("phone") || !verificateFiled("birthday") ||
					!verificateFiled("dept") || !verificateFiled("job")) {
					return;
				}
				let uId = $('#uid').val()
				let uName = $('#username').val().trim()
				let uPassword = $('#password').val().trim()
				let sex = $('#sex').attr("checked") ? 1 : 2;
				let uTelephone = $('#phone').val().trim()
				let birthday = $('#birthday').val()+' 00:00:00'
				let deptId = $('#dept').attr("value")
				let jobId = $('#job').attr("value")
				let statusId=$('#statuSelect').val()
				let obj = {
					uId,
					uPassword,
					uName,
					sex,
					uTelephone,
					birthday,
					deptId,
					jobId,
					statusId
				}
				axiosRequest1("post", "/user/update", obj).then(res => {
					const {
						code,
						message
					} = res.data
					let warninfo = $('#warninfo')
					warninfo.text("修改成功")
					warninfo.show()
					setTimeout(() => {
						warninfo.hide()
					}, 2000)
					if (code !== 200) randomUid()
				}, error => {
					console.log(error);
				})
			}
		</script>
		<style type="text/css">
			#birthday {
				padding-right: 0;
				height: 32px;
				line-height: 32px;
			}
		</style>
	</head>

	<body>
		<div id="warninfo" style="width: 200px;height: 39px; background-color: #eebe77;display: none;position: fixed;
		top: 20px;left: 0;right: 0;margin: 0 auto;border-radius: 5px;font-size: 16px;line-height: 39px;text-align: center;">
		</div>
		<div class="place"> <span>位置：</span>
			<ul class="placeul">
				<li><a href="userList.html">系统管理</a></li>
				<li><a href="userList.html">用户管理</a></li>
				<li><a href="#">修改</a></li>
			</ul>
		</div>
		<div class="formbody">
			<div class="formtitle"><span>员工信息</span></div>
			<ul class="forminfo">
				<li>
					<label>员工编号</label>
					<input name="" type="text" id="uid" class="dfinput" readonly />

				</li>
				<li>
					<label>员工姓名</label>
					<input name="username" id="username" type="text" class="dfinput"
						onblur="verificateFiled('username')" />
					<i id="usernamei"></i>
				</li>
				<li>
					<label>密码</label>
					<input name="password" id="password" type="password" class="dfinput"
						onblur="verificateFiled('password')" />
					<i id="passwordi"></i>
				</li>
				<li>
					<label>性别</label>
					<cite>
						<input name="gender" type="radio" value="1" id="male" />男
						&nbsp;&nbsp;&nbsp;&nbsp;
						<input name="gender" type="radio" value="2" id="womale" />女
					</cite>
				</li>
				<li>
					<label>联系方式</label>
					<input name="phone" id="phone" type="text" class="dfinput" onblur="verificateFiled('phone')" />
					<i id="phonei"></i>
				</li>
				<li>
					<label>出生年月</label>
					<input name="birthday" class="dfinput laydate-icon" id="birthday"
						onblur="verificateFiled('birthday')">
					<i id="birthdayi"></i>
				</li>
				<li>
					<label>所属部门</label>
					<select name="dept" id="dept" class="dfselect" onblur="verificateFiled('dept')">
					</select>
					<i id="depti"></i>
				</li>
				<li>
					<label>职位</label>
					<select name="job" id="job" class="dfselect" onblur="verificateFiled('job')">
					</select>
					<i id="jobi"></i>
				</li>
				<li>
					<label>状态</label>
					<select name="" class="dfselect" id="statuSelect">
						<option value="1" id="sattu-one">在职</option>
						<option value="0" id="statu-zero">离职</option>
					</select>
				</li>
				<li>
					<label>&nbsp;</label>
					<input name="" type="button" class="btn" value="确认保存" onclick="updateUser()" />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input name="" type="button" class="btn" value="返回" onclick="window.history.go(-1);" />
				</li>
			</ul>
		</div>
		<script type="text/javascript">
			! function() {
				laydate.skin('molv'); //切换皮肤，请查看skins下面皮肤库
				laydate({
					elem: '#birthday'
				}); //绑定元素
			}();
		</script>
	</body>
</html>
